package com.pms.utils;


import java.util.*;
import java.text.*;



/** Utility class of static methods for formatting and parsing the
 * objects in bobe. Initially for JSP formatting & parsing.
 * Th methods use the UserToken to obtain locale & timezone information.
 *
 */
public class Formatter {

//---- GENERATED CODE START -----------

  //------------------------------------
  // Attribute Name Definitions
  public static final String SORTABLEDATETIMEFORMAT = "Formatter_SortableDateTimeFormat";
  public static final String SHORTTIMEFORMAT = "Formatter_ShortTimeFormat";
  public static final String MEDIUMTIMEFORMAT = "Formatter_MediumTimeFormat";
  public static final String LONGTIMEFORMAT = "Formatter_LongTimeFormat";
  public static final String SHORTDATEFORMAT = "Formatter_ShortDateFormat";
  public static final String MEDIUMDATEFORMAT = "Formatter_MediumDateFormat";
  public static final String LONGDATEFORMAT = "Formatter_LongDateFormat";
  public static final String SHORTDATETIMEFORMAT = "Formatter_ShortDateTimeFormat";
  public static final String MEDIUMDATETIMEFORMAT = "Formatter_MediumDateTimeFormat";
  public static final String LONGDATETIMEFORMAT = "Formatter_LongDateTimeFormat";
  public static final String SORTABLEDATEFORMAT = "Formatter_SortableDateFormat";
  public static final String NUMBERFORMAT = "Formatter_NumberFormat";
  public static final String CURRENCYFORMAT = "Formatter_CurrencyFormat";
  public static final String PLAINCURRENCYFORMAT = "Formatter_PlainCurrencyFormat";

  


  //------------------------------------
  // Attribute Set & Get Methods

  /** Sets the value for the attribute SortableDateTimeFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setSortableDateTimeFormat(DateFormat aValue) { mSortableDateTimeFormat = aValue; return this; }

  /** Returns the value for the attribute SortableDateTimeFormat.
   * @return DateFormat  the SortableDateTimeFormat attribute.
   */
  public DateFormat getSortableDateTimeFormat() { return mSortableDateTimeFormat; }

  /** Sets the value for the attribute ShortTimeFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setShortTimeFormat(DateFormat aValue) { mShortTimeFormat = aValue; return this; }

  /** Returns the value for the attribute ShortTimeFormat.
   * @return DateFormat  the ShortTimeFormat attribute.
   */
  public DateFormat getShortTimeFormat() { return mShortTimeFormat; }

  /** Sets the value for the attribute MediumTimeFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setMediumTimeFormat(DateFormat aValue) { mMediumTimeFormat = aValue; return this; }

  /** Returns the value for the attribute MediumTimeFormat.
   * @return DateFormat  the MediumTimeFormat attribute.
   */
  public DateFormat getMediumTimeFormat() { return mMediumTimeFormat; }

  /** Sets the value for the attribute LongTimeFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setLongTimeFormat(DateFormat aValue) { mLongTimeFormat = aValue; return this; }

  /** Returns the value for the attribute LongTimeFormat.
   * @return DateFormat  the LongTimeFormat attribute.
   */
  public DateFormat getLongTimeFormat() { return mLongTimeFormat; }

  /** Sets the value for the attribute ShortDateFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setShortDateFormat(DateFormat aValue) { mShortDateFormat = aValue; return this; }

  /** Returns the value for the attribute ShortDateFormat.
   * @return DateFormat  the ShortDateFormat attribute.
   */
  public DateFormat getShortDateFormat() { return mShortDateFormat; }

  /** Sets the value for the attribute MediumDateFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setMediumDateFormat(DateFormat aValue) { mMediumDateFormat = aValue; return this; }

  /** Returns the value for the attribute MediumDateFormat.
   * @return DateFormat  the MediumDateFormat attribute.
   */
  public DateFormat getMediumDateFormat() { return mMediumDateFormat; }

  /** Sets the value for the attribute LongDateFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setLongDateFormat(DateFormat aValue) { mLongDateFormat = aValue; return this; }

  /** Returns the value for the attribute LongDateFormat.
   * @return DateFormat  the LongDateFormat attribute.
   */
  public DateFormat getLongDateFormat() { return mLongDateFormat; }

  /** Sets the value for the attribute ShortDateTimeFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setShortDateTimeFormat(DateFormat aValue) { mShortDateTimeFormat = aValue; return this; }

  /** Returns the value for the attribute ShortDateTimeFormat.
   * @return DateFormat  the ShortDateTimeFormat attribute.
   */
  public DateFormat getShortDateTimeFormat() { return mShortDateTimeFormat; }

  /** Sets the value for the attribute MediumDateTimeFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setMediumDateTimeFormat(DateFormat aValue) { mMediumDateTimeFormat = aValue; return this; }

  /** Returns the value for the attribute MediumDateTimeFormat.
   * @return DateFormat  the MediumDateTimeFormat attribute.
   */
  public DateFormat getMediumDateTimeFormat() { return mMediumDateTimeFormat; }

  /** Sets the value for the attribute LongDateTimeFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setLongDateTimeFormat(DateFormat aValue) { mLongDateTimeFormat = aValue; return this; }

  /** Returns the value for the attribute LongDateTimeFormat.
   * @return DateFormat  the LongDateTimeFormat attribute.
   */
  public DateFormat getLongDateTimeFormat() { return mLongDateTimeFormat; }

  /** Sets the value for the attribute SortableDateFormat.
   * @param DateFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setSortableDateFormat(DateFormat aValue) { mSortableDateFormat = aValue; return this; }

  /** Returns the value for the attribute SortableDateFormat.
   * @return DateFormat  the SortableDateFormat attribute.
   */
  public DateFormat getSortableDateFormat() { return mSortableDateFormat; }

  /** Sets the value for the attribute NumberFormat.
   * @param NumberFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setNumberFormat(NumberFormat aValue) { mNumberFormat = aValue; return this; }

  /** Returns the value for the attribute NumberFormat.
   * @return NumberFormat  the NumberFormat attribute.
   */
  public NumberFormat getNumberFormat() { return mNumberFormat; }

  /** Sets the value for the attribute CurrencyFormat.
   * @param NumberFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setCurrencyFormat(NumberFormat aValue) { mCurrencyFormat = aValue; return this; }

  /** Returns the value for the attribute PlainCurrencyFormat.
   * @return NumberFormat  the CurrencyFormat attribute.
   */
  public NumberFormat getCurrencyFormat() { return mCurrencyFormat; }

  /** Sets the value for the attribute CurrencyFormat.
   * @param NumberFormat  the value to set.
   * @return  reference to entity.
   */
  public Formatter setPlainCurrencyFormat(NumberFormat aValue) { mPlainCurrencyFormat = aValue; return this; }

  /** Returns the value for the attribute PlainCurrencyFormat.
   * @return NumberFormat  the CurrencyFormat attribute.
   */
  public NumberFormat getPlainCurrencyFormat() { return mPlainCurrencyFormat; }


  /** Returns a string representation of the the entity object.
   *
   * @return String.
   *
   */
  public String toString() {

    StringBuffer sb = new StringBuffer();

    sb.append("SortableDateTimeFormat=").append(mSortableDateTimeFormat).append(",");
    sb.append("ShortTimeFormat=").append(mShortTimeFormat).append(",");
    sb.append("MediumTimeFormat=").append(mMediumTimeFormat).append(",");
    sb.append("LongTimeFormat=").append(mLongTimeFormat).append(",");
    sb.append("ShortDateFormat=").append(mShortDateFormat).append(",");
    sb.append("MediumDateFormat=").append(mMediumDateFormat).append(",");
    sb.append("LongDateFormat=").append(mLongDateFormat).append(",");
    sb.append("ShortDateTimeFormat=").append(mShortDateTimeFormat).append(",");
    sb.append("MediumDateTimeFormat=").append(mMediumDateTimeFormat).append(",");
    sb.append("LongDateTimeFormat=").append(mLongDateTimeFormat).append(",");
    sb.append("SortableDateFormat=").append(mSortableDateFormat).append(",");
    sb.append("NumberFormat=").append(mNumberFormat).append(",");
    sb.append("CurrencyFormat=").append(mCurrencyFormat).append(",");
    sb.append("PlainCurrencyFormat=").append(mCurrencyFormat).append(",");

    return sb.toString();
  }

//---- GENERATED CODE END -----------
  public static final String SORTABLE_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

  public static final String SHORTTIMESPANFORMAT = "SHORTTIMESPANFORMAT";
  public static final String LONGTIMESPANFORMAT = "LONGTIMESPANFORMAT";

  /** Return the given currency (double) as a String localised to the SiteView locale
   *
   * @param aCurrencyValue   double currency value
   *
   * @return String representation of localised number
   *
   */
  public String formatCurrency(double aCurrencyValue) {
    return mCurrencyFormat.format(DoubleUtility.makeZeroPositive(aCurrencyValue));
  }

  /** Return the given currency (double) as a String with 2 decimal places
   * but no number seperator.
   *
   * @param aCurrencyValue   double currency value
   *
   * @return String representation of localised number
   *
   */
  public String formatPlainCurrency(double aCurrencyValue) {
    return mPlainCurrencyFormat.format(DoubleUtility.makeZeroPositive(aCurrencyValue));
  }

  /** Return the given timespan  as a String in a proper format support two format at the moment.
   * SHORTTIMESPANFORMAT and LONGTIMESPANFORMAT. this only work for day,hour,minute and second units.
   *
   * @param aTimeSpan   a time span
   *
   * @return a formatted time span string.
   *
   */
  public String formatTimeSpan(TimeSpan aTimeSpan,String formatString) {
      String timeSpan ="" ;
      char[] formatArray = formatString.toCharArray();
      int len = formatString.length();
      boolean singleQuoteOn = false;

      //Trace.Log("DEBUG:Formatter",Trace.LOW,"Cehck==>"+formatString);

      if(formatString.equals(SHORTTIMESPANFORMAT)){
          if(aTimeSpan.getFieldAccum(TimeSpan.DAY) > 0){
              timeSpan = aTimeSpan.getFieldAccum(TimeSpan.DAY) + (aTimeSpan.getField(TimeSpan.DAY)==1?"&nbsp;day,&nbsp;":"&nbsp;days,&nbsp;") + aTimeSpan.getField(TimeSpan.HOUR)+ ":"+ (aTimeSpan.getField(TimeSpan.MINUTE)<10?"0":"") + aTimeSpan.getField(TimeSpan.MINUTE);
          }
          else if(aTimeSpan.getField(TimeSpan.HOUR) > 0 || aTimeSpan.getField(TimeSpan.MINUTE) >0){
             timeSpan = aTimeSpan.getField(TimeSpan.HOUR)+ ":"+ +aTimeSpan.getField(TimeSpan.MINUTE);
          }else{
              timeSpan = "Item&nbsp;Closed";
          }
      }else if(formatString.equals(LONGTIMESPANFORMAT)){
          if(aTimeSpan.getFieldAccum(TimeSpan.MINUTE) < 0){
              timeSpan = aTimeSpan.getFieldAccum(TimeSpan.DAY) + (aTimeSpan.getField(TimeSpan.DAY)==1?"&nbsp;day,&nbsp;":"&nbsp;days,&nbsp;") + aTimeSpan.getField(TimeSpan.HOUR)+ ":"+ (aTimeSpan.getField(TimeSpan.MINUTE)<10?"0":"")+ aTimeSpan.getField(TimeSpan.MINUTE);
          }else{
              timeSpan = "Item&nbsp;Closed";
          }
      }else {
          for (int cur = 0 ; cur < len ; cur++) {

              if(formatArray[cur] == '\'') {
                  singleQuoteOn = !singleQuoteOn ;
                  continue;
              }

              if(!singleQuoteOn) {
                  switch (formatArray[cur]) {

                      case 'd':
                          if(cur < (len -1)){
                              if(formatArray[cur+1] == 'd'){
                                  timeSpan = timeSpan + (aTimeSpan.getFieldAccum(TimeSpan.DAY)<10?"0":"")+aTimeSpan.getFieldAccum(TimeSpan.DAY);
                                  cur++;
                              }
                              else
                                timeSpan = timeSpan + aTimeSpan.getFieldAccum(TimeSpan.DAY);
                           }
                           else
                             timeSpan = timeSpan + aTimeSpan.getField(TimeSpan.DAY);
                          if(aTimeSpan.getFieldAccum(TimeSpan.DAY) <0)
                             timeSpan = "Item&nbsp;Closed";
                      break;

                      case 'H':
                          if(cur < (len -1)){
                              if(formatArray[cur+1] == 'H'){
                                  timeSpan = timeSpan + (aTimeSpan.getField(TimeSpan.HOUR)<10?"0":"")+ aTimeSpan.getField(TimeSpan.HOUR);
                                  cur++;
                              }
                              else
                                timeSpan = timeSpan + aTimeSpan.getField(TimeSpan.HOUR);
                          }
                          else
                            timeSpan = timeSpan + aTimeSpan.getField(TimeSpan.HOUR);

                          if(aTimeSpan.getFieldAccum(TimeSpan.HOUR) <0)
                             timeSpan = "Item&nbsp;Closed";
                      break;

                      case 'm':
                          if(cur < (len -1)){
                              if(formatArray[cur+1] == 'm'){
                                  timeSpan = timeSpan + (aTimeSpan.getField(TimeSpan.MINUTE)<10?"0":"") + aTimeSpan.getField(TimeSpan.MINUTE);
                                  cur++;
                             }
                             else
                                timeSpan = timeSpan + aTimeSpan.getField(TimeSpan.MINUTE);
                          }
                          else
                            timeSpan = timeSpan + aTimeSpan.getField(TimeSpan.MINUTE);

                          if(aTimeSpan.getFieldAccum(TimeSpan.MINUTE) <0)
                             timeSpan = "Item&nbsp;Closed";
                      break;

                      case 's':
                          if(cur < (len -1)){
                              if(formatArray[cur+1] == 's'){
                                  timeSpan = timeSpan + (aTimeSpan.getField(TimeSpan.SECOND)<10?"0":"") + aTimeSpan.getField(TimeSpan.SECOND);
                                  cur++;
                              }
                              else
                                timeSpan = timeSpan + aTimeSpan.getField(TimeSpan.SECOND);
                          }
                          else
                             timeSpan = timeSpan + aTimeSpan.getField(TimeSpan.SECOND);

                          if(aTimeSpan.getFieldAccum(TimeSpan.SECOND) <0)
                             timeSpan = "Item&nbsp;Closed";
                      break;
                  }
              }
              else{
                  timeSpan = timeSpan + formatArray[cur];
              }
          }
      }
      return timeSpan;
  }

  /** Return the given double as a String localised to the SiteView locale
   *
   * @param aNumber   double to format
   *
   * @return String representation of localised number
   *
   */
  public String formatNumber(double aNumber) {
    return mNumberFormat.format(aNumber);
  }

  /** Parse an input string into a double.
   *
   * @param aNumber    String to parse into a double
   *
   * @return the double parsed from the String
   *
   */
  public double parseDouble(String aNumber) throws ParseException {
    return mNumberFormat.parse(aNumber).doubleValue();
  }

  /** Return the given int as a String localised to the SiteView locale
   *
   * @param aNumber   integer to format
   *
   * @return String representation of localised number
   *
   */
  public String formatNumber(int aNumber) {
    return mNumberFormat.format(aNumber);
  }

  /** Parse an input string into a int.
   *
   * @param aNumber    String to parse into a int
   *
   * @return the int parsed from the String
   *
   */
  public int parseInt(String aNumber) throws ParseException {
    return mNumberFormat.parse(aNumber).intValue();
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.SHORT format of the SiteView Locale and TimeZone.
   * Uses a DateTimeFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatShortDateTime(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mShortDateTimeFormat.format(aCalendar.getTime());
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.SHORT format of the SiteView Locale and TimeZone.
   * Uses a DateFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatShortDate(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mShortDateFormat.format(aCalendar.getTime());
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.SHORT format of the SiteView Locale and TimeZone.
   * Uses a TimeFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatShortTime(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mShortTimeFormat.format(aCalendar.getTime());
  }

  /** Parse an input string in DateFormat.SHORT to create a Calendar,
   * according to the SiteView Locale and TimeZone.
   *
   * @param Date        String to parse into a Calendar
   *
   * @return Calendar  the Calendar parsed from the string
   *
   */
  public Calendar parseShortDate(String aDate) throws java.text.ParseException {
    return CalendarUtility.createCalendar(mShortDateFormat.parse(aDate));
  }

  /** Parse an input string in DateFormat.SHORT to create a Calendar,
   * according to the SiteView Locale and TimeZone.
   *
   * @param Date        String to parse into a Calendar
   *
   * @return Calendar  the Calendar parsed from the string
   *
   */
  public Calendar parseShortDateTime(String aDate) throws java.text.ParseException {
    return CalendarUtility.createCalendar(mShortDateTimeFormat.parse(aDate));
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.MEDIUM format of the SiteView Locale and TimeZone.
   * Uses a DateFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatMediumDateTime(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mMediumDateTimeFormat.format(aCalendar.getTime());
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.MEDIUM format of the SiteView Locale and TimeZone.
   * Uses a DateFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatMediumDate(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mMediumDateFormat.format(aCalendar.getTime());
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.MEDIUM format of the SiteView Locale and TimeZone.
   * Uses a TimeFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatMediumTime(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mMediumTimeFormat.format(aCalendar.getTime());
  }

  /** Parse an input string in DateFormat.MEDIUM to create a Calendar,
   * according to the SiteView Locale and TimeZone.
   *
   * @param Date        String to parse into a Calendar
   *
   * @return Calendar  the Calendar parsed from the string
   *
   */
  public Calendar parseMediumDateTime(String aDate) throws java.text.ParseException {
    return CalendarUtility.createCalendar(mMediumDateTimeFormat.parse(aDate));
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.LONG format of the SiteView Locale and TimeZone.
   * Uses a DateFormat cached in a SiteView for performance.
   *
   * @param UserToken   UserToken containing references to localisation objects
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatLongDateTime(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mLongDateTimeFormat.format(aCalendar.getTime());
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.LONG format of the SiteView Locale and TimeZone.
   * Uses a DateFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatLongDate(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mLongDateFormat.format(aCalendar.getTime());
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.LONG format of the SiteView Locale and TimeZone.
   * Uses a TimeFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatLongTime(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mLongTimeFormat.format(aCalendar.getTime());
  }

  /** Parse a Calendar from a String using a custom format
   * and the SiteView TimeZone.
   *
   * @param String representation of localised date
   * @param String  the custom date/time format
   *
   * @return Calendar
   *
   */
  public Calendar parseCustomTime(String aDateTimeString, String aFormat ) throws java.text.ParseException {

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(aFormat);
    simpleDateFormat.setTimeZone(mLongTimeFormat.getTimeZone());

    return CalendarUtility.createCalendar(simpleDateFormat.parse(aDateTimeString.trim()));
  }

  /** Return a String representing the given UTC date in the
   * DateFormat.LONG format of the SiteView Locale and TimeZone.
   * Uses a TimeFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatCustomTime( Calendar aCalendar, String aFormat )
  {
    if ( aCalendar==null ) return null;
    else
    {
      SimpleDateFormat sdf = new SimpleDateFormat( aFormat );
      sdf.setTimeZone( mLongTimeFormat.getTimeZone() );

      return sdf.format( aCalendar.getTime() );
    }
  }

  /** Parse an input string in DateFormat.LONG to create a Calendar,
   * according to the SiteView Locale and TimeZone.
   *
   * @param Date        String to parse into a Calendar
   *
   * @return Calendar  the Calendar parsed from the string
   *
   */
  public Calendar parseLongDateTime(String aDate) throws java.text.ParseException {
    return CalendarUtility.createCalendar(mLongDateTimeFormat.parse(aDate));
  }

  /** Return a String representing the given UTC date in the
   * bobe standard sortable Date/Time format using SiteView TimeZone.
   * Uses a DateFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatSortableDateTime(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mSortableDateTimeFormat.format(aCalendar.getTime());
  }

  /** Parse an input string in the bobe standard sortable Date/Time format to create a Calendar,
   * according to the SiteView TimeZone.
   * Uses a DateFormat cached in a SiteView for performance.
   *
   * @param Date       String to parse into a Calendar
   *
   * @return Calendar  the Calendar parsed from the string
   *
   */
  public Calendar parseSortableDateTime(String aDate) throws java.text.ParseException {
    return CalendarUtility.createCalendar(mSortableDateTimeFormat.parse(aDate));
  }

  /** Return a String representing the given UTC date in the
   * bobe standard sortable Date format using SiteView TimeZone.
   * Uses a DateFormat cached in a SiteView for performance.
   *
   * @param Calendar    Date to format
   *
   * @return String representation of localised date
   *
   */
  public String formatSortableDate(Calendar aCalendar) {
    if(aCalendar == null)
      return null;
    else
      return mSortableDateFormat.format(aCalendar.getTime());
  }

  /** Parse an input string in the bobe standard sortable Date format to create a Calendar,
   * according to the SiteView TimeZone.
   * Uses a DateFormat cached in a SiteView for performance.
   *
   * @param Date       String to parse into a Calendar
   *
   * @return Calendar  the Calendar parsed from the string
   *
   */
  public Calendar parseSortableDate(String aDate) throws java.text.ParseException {
    return CalendarUtility.createCalendar(mSortableDateFormat.parse(aDate));
  }

  /** check if the time in the date is a 12 hours format with AM or PM or not.
   *
   *
   * @param String       input date
   *
   * @return true if the date is in 12 hours format, else return false.
   *
   *
   */
   public static boolean is12HoursTimeFormat(String aDate) {

      if(aDate.toUpperCase().matches("/AM|PM/"))
        return true ;
      else
        return false;
  }


  //----------------------------------------------------------
  private DateFormat mSortableDateTimeFormat = new SimpleDateFormat(SORTABLE_DATE_TIME_FORMAT);

  private DateFormat mShortTimeFormat = null;
  private DateFormat mMediumTimeFormat = null;
  private DateFormat mLongTimeFormat = null;

  private DateFormat mShortDateFormat = null;
  private DateFormat mMediumDateFormat = null;
  private DateFormat mLongDateFormat = null;

  private DateFormat mShortDateTimeFormat = null;
  private DateFormat mMediumDateTimeFormat = null;
  private DateFormat mLongDateTimeFormat = null;

  private DateFormat mSortableDateFormat = null;
  private NumberFormat mNumberFormat = null;
  private NumberFormat mCurrencyFormat = null;
  private NumberFormat mPlainCurrencyFormat = null;
}
